package org.example.lotterysystem.common.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.example.lotterysystem.common.utils.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

//用户登录拦截器
@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userToken = request.getHeader("user_token");
        System.out.println(request.getRequestURI());
        log.info("获取的token,token:"+userToken);
        boolean result = JwtUtils.checkToken(userToken);
        if (result) {
            return true;
        }
        response.setStatus(401);
        return false;
    }
}
